import pymysql
# 调用env.py文件中的变量连接数据库
from env import MYSQL_HOST
from env import MYSQL_DATABASE
from env import MYSQL_PASSWORD
from env import MYSQL_USERNAME

MYSQL_HOST = MYSQL_HOST
MYSQL_DATABASE = MYSQL_DATABASE
MYSQL_USERNAME = MYSQL_USERNAME
MYSQL_PASSWORD = MYSQL_PASSWORD

connection = pymysql.connect(user=MYSQL_USERNAME,
                             password=MYSQL_PASSWORD,
                             database=MYSQL_DATABASE,
                             host=MYSQL_HOST)

cursor = connection.cursor()

sql = "insert into user" \
      " (user_id,user_name,user_email,user_password) " \
      " values" \
      " (%s,%s,%s,%s)"

id = 2222
name = 'wang'
email = 123123123
password = 123123

args = (id, name, email, password)

result = cursor.execute(sql, args)
print(result)

connection.commit()

cursor.close()
connection.close()
